﻿using DongFangGuoKai.WMS.IApiService;
using DongFangGuoKai.WMSPlatform.Commn;
using DongFangGuoKai.WMSPlatform.Commn.AppsetingsModule;
using DongFangGuoKai.WMSPlatform.Commn.HttpModule;
using DongFangGuoKai.WMSPlatform.Domain.Enums;
using DongFangGuoKai.WMSPlatform.Domain.LIMSModels;
using RestSharp;

namespace DongFangGuoKai.WMS.ApiService
{
    /// <summary>
    /// 检化验接口
    /// </summary>
    public class LIMSService : ILIMSService
    {
        public string RequstUrl;
        public LIMSService(ICtmHttpClient client)
        {
            RequstUrl = ConfigManageHelper.LIMSServicePath;
            Client = client;
        }
        public ICtmHttpClient Client { get; }

        /// <summary>
        /// 查询委托单状态
        /// </summary>
        /// <returns></returns>
        public LIMSResultRespons<LIMSTrustInfoModel> QueryTrustInfo(string orderNo)
        {
            string url = BulidRequstUrl(LIMSRequestType.OrderQuery);
            return Retry.Execute(() =>
              {
                  return Client.Post<LIMSResultRespons<LIMSTrustInfoModel>>(url, new QueryParameter("orderNo", orderNo));
              }, TimeSpan.FromSeconds(3),1);
        }
        /// <summary>
        /// 样品流转接口
        /// </summary>
        /// <returns></returns>
        public LIMSResultRespons SampleCirculation(List<SampleCirculationModel> sampleModel)
        {
            string url = BulidRequstUrl(LIMSRequestType.Circulation);
            return Retry.Execute(() =>
            {
                return Client.Post<LIMSResultRespons>(url, sampleModel);
            }, TimeSpan.FromSeconds(3));
        }

        /// <summary>
        /// 样品上架
        /// </summary>
        /// <returns></returns>
        public LIMSResultRespons SamplePutaway(List<SamplePutawayModel> sampleModel)
        {
            string url = BulidRequstUrl(LIMSRequestType.Putaway);
            return Retry.Execute(() =>
            {
                return Client.Post<LIMSResultRespons>(url, sampleModel);
            }, TimeSpan.FromSeconds(3));
        }

        private string BulidRequstUrl(LIMSRequestType lIMSRequestType)
        {
            switch (lIMSRequestType)
            {
                //委托单状态查询
                case LIMSRequestType.OrderQuery:
                    return RequstUrl + "/wms/sample/queryOrder";
                //样品流转接口
                case LIMSRequestType.Circulation:
                    return RequstUrl + "/wms/sample/circulation";
                //样品上架
                case LIMSRequestType.Putaway:
                    return RequstUrl + "/wms/sample/putaway";
                default:
                    break;
            }
            return "";
        }

    }
}
